<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>编辑图书 - 图书管理系统</title>
  <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
  <div class="row justify-content-center">
    <div class="col-md-8">
      <div class="card">
        <div class="card-header">
          <h4 class="card-title mb-0">
            <i class="fas fa-edit"></i> 编辑图书
          </h4>
        </div>
        <div class="card-body">
          <form th:action="@{/books/edit/{id}(id=${book.id})}" th:object="${book}" method="post">
            <!-- 书名 -->
            <div class="mb-3">
              <label for="title" class="form-label">
                <i class="fas fa-book"></i> 书名 <span class="text-danger">*</span>
              </label>
              <input type="text" class="form-control" id="title" th:field="*{title}"
                     placeholder="请输入书名" required>
              <div th:if="${#fields.hasErrors('title')}" class="text-danger">
                <small th:errors="*{title}"></small>
              </div>
            </div>

            <!-- 作者 -->
            <div class="mb-3">
              <label for="author" class="form-label">
                <i class="fas fa-user"></i> 作者 <span class="text-danger">*</span>
              </label>
              <input type="text" class="form-control" id="author" th:field="*{author}"
                     placeholder="请输入作者" required>
              <div th:if="${#fields.hasErrors('author')}" class="text-danger">
                <small th:errors="*{author}"></small>
              </div>
            </div>

            <!-- ISBN -->
            <div class="mb-3">
              <label for="isbn" class="form-label">
                <i class="fas fa-barcode"></i> ISBN <span class="text-danger">*</span>
              </label>
              <input type="text" class="form-control" id="isbn" th:field="*{isbn}"
                     placeholder="请输入ISBN" required>
              <div th:if="${#fields.hasErrors('isbn')}" class="text-danger">
                <small th:errors="*{isbn}"></small>
              </div>
            </div>

            <!-- 出版年份 -->
            <div class="mb-3">
              <label for="publicationYear" class="form-label">
                <i class="fas fa-calendar"></i> 出版年份 <span class="text-danger">*</span>
              </label>
              <input type="number" class="form-control" id="publicationYear"
                     th:field="*{publicationYear}"
                     placeholder="请输入出版年份"
                     min="1900" max="2030" required>
              <div th:if="${#fields.hasErrors('publicationYear')}" class="text-danger">
                <small th:errors="*{publicationYear}"></small>
              </div>
            </div>

            <!-- 出版社 -->
            <div class="mb-3">
              <label for="publisher" class="form-label">
                <i class="fas fa-building"></i> 出版社
              </label>
              <input type="text" class="form-control" id="publisher" th:field="*{publisher}"
                     placeholder="请输入出版社">
            </div>

            <!-- 创建时间（只读） -->
            <div class="mb-3">
              <label class="form-label">
                <i class="fas fa-clock"></i> 创建时间
              </label>
              <input type="text" class="form-control"
                     th:value="${#temporals.format(book.createTime, 'yyyy-MM-dd HH:mm:ss')}"
                     readonly>
            </div>

            <!-- 按钮 -->
            <div class="d-grid gap-2 d-md-flex justify-content-md-end">
              <a th:href="@{/books}" class="btn btn-secondary me-md-2">
                <i class="fas fa-arrow-left"></i> 返回列表
              </a>
              <button type="submit" class="btn btn-primary">
                <i class="fas fa-save"></i> 更新图书
              </button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
</body>
</html>